#include "Audio.h"


/*Audio::Audio(void)
{
}


Audio::~Audio(void)
{
}*/
void Audio::FmodErrorCheck(FMOD_RESULT result)	// this is an error handling function
{						// for FMOD errors
	if (result != FMOD_OK)
	{
		printf("FMOD error! (%d) %s\n", result, FMOD_ErrorString(result));
		exit(-1);
	}
}


void Audio::initializeSound() {
	result = System_Create(&fmodSystem);
	FmodErrorCheck(result);
	result = fmodSystem->init(NUM_CHANNELS, FMOD_INIT_NORMAL, 0);
	FmodErrorCheck(result);
}

void Audio::updateSound() {
	result = fmodSystem->update();
}


void Audio::loadSounds() {
	result = fmodSystem->createSound("sounds/Dark.mp3", FMOD_DEFAULT, 0, &sound1);
	FmodErrorCheck(result);
	sound1->setMode(FMOD_LOOP_OFF);


	result = fmodSystem->createSound("sounds/Buried.mp3", FMOD_DEFAULT, 0, &sound2);
	FmodErrorCheck(result);
	sound2->setMode(FMOD_LOOP_OFF);
	//soundtrack->setMode(FMOD_LOOP_NORMAL);

}

void Audio::playSound1() {
	channel->setVolume(0.5f);
	result = fmodSystem->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
	FmodErrorCheck(result);
}

void Audio::playSound2() {
	channel->setVolume(0.5f);
	result = fmodSystem->playSound(FMOD_CHANNEL_FREE, sound2, false, &channel);
	FmodErrorCheck(result);
}

void Audio::stopSound1() {
}

int Audio::getTick(){
	return tick;
}

void Audio::setTick(int t){
	tick = t;
}